Skip to content

Attach SdkResourceProvider in autoconfigure and declarative config - #9060

Open
rooks-ns wants to merge 1 commit into
open-telemetry:mainfrom
rooks-ns:feat/attach-sdk-resource-provider
Open

rooks-ns wants to merge 1 commit into
open-telemetry:mainfrom
rooks-ns:feat/attach-sdk-resource-provider

Conversation

@rooks-ns

Copy link
Copy Markdown
Contributor

Description

Implements follow-up 1 from #8865 by attaching SdkResourceProvider to SdkMeterProvider, SdkLoggerProvider, and SdkTracerProvider instead of a static Resource.

Changes

  • Declarative Config: Attaches the resolved SdkResourceProvider via Sdk*ProviderUtil.setSdkResourceProvider(...) across all signal builders.
  • Autoconfigure & Builders: Adds package-private setDefaultSdkResourceProvider to SdkTracerProviderBuilder, SdkMeterProviderBuilder, and SdkLoggerProviderBuilder. Autoconfigure supplies the baseline provider without tripping the strict IllegalStateException guard if a user customizer subsequently overrides or merges resources via .setResource(...) or .addResource(...).
  • Guard Integrity: Direct, explicit calls to setSdkResourceProvider continue to fail-fast against conflicting setResource/addResource invocations.
  • Tests: Added coverage for default provider delegation, customizer overrides, and cross-signal provider sharing.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-12-04 22:34 UTC

Respond to 4 review items (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1, 2, 3, 4
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.58879% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.52%. Comparing base (a92b644) to head (e5d48e7).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...metry/sdk/logs/internal/SdkLoggerProviderUtil.java 75.00% 2 Missing ⚠️
...try/sdk/metrics/internal/SdkMeterProviderUtil.java 75.00% 2 Missing ⚠️
...etry/sdk/trace/internal/SdkTracerProviderUtil.java 75.00% 2 Missing ⚠️
...entelemetry/sdk/logs/SdkLoggerProviderBuilder.java 95.23% 0 Missing and 1 partial ⚠️
...telemetry/sdk/metrics/SdkMeterProviderBuilder.java 95.23% 0 Missing and 1 partial ⚠️
...ntelemetry/sdk/trace/SdkTracerProviderBuilder.java 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9060      +/-   ##
============================================
- Coverage     90.56%   90.52%   -0.04%     
- Complexity    11220    11265      +45     
============================================
  Files          1032     1040       +8     
  Lines         30599    30766     +167     
  Branches       4010     4021      +11     
============================================
+ Hits          27711    27851     +140     
- Misses         1913     1934      +21     
- Partials        975      981       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Update autoconfigure and declarative configuration to attach a shared
SdkResourceProvider to SdkTracerProvider, SdkMeterProvider, and
SdkLoggerProvider instead of a static Resource.

- In declarative config, use Sdk*ProviderUtil.setSdkResourceProvider to
  attach the provider built from the resolved resource model.
- In autoconfigure, introduce and use setDefaultSdkResourceProvider on the
  signal provider builders to set the baseline resource provider while
  allowing signal-specific customizers to override or merge resources via
  setResource or addResource without throwing IllegalStateException.
- Preserve fail-fast guards when setSdkResourceProvider and
  setResource/addResource are explicitly configured on the same builder.
- Add unit tests verifying default provider usage, customizer overrides,
  and cross-signal provider sharing.
@rooks-ns
rooks-ns force-pushed the feat/attach-sdk-resource-provider branch from a01ffca to e5d48e7 Compare December 3, 2026 17:31
@rooks-ns
rooks-ns marked this pull request as ready for review December 3, 2026 18:29
@rooks-ns
rooks-ns requested a review from a team as a code owner December 3, 2026 18:29

@jack-berg jack-berg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this - i've been meaning to do this.

Comment on lines 125 to +129
}
this.resource = this.resource.merge(resource);
this.resourceExplicitlySet = true;
Resource current = resourceProvider != null ? resourceProvider.getResource() : this.resource;
this.resource = current.merge(resource);
this.resourceProvider = null;
this.resourceSource = ResourceSource.EXPLICIT_RESOURCE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tracer customizer calling addResource(Resource.empty()) replaces the shared SdkResourceProvider with a separate provider despite leaving the resource unchanged. setResource() with an equivalent resource does the same. ExtendedOpenTelemetrySdk.getSdkResourceProvider() still succeeds because its resolver compares the providers' resources with .equals(). If that resolver required provider instance equality, it would throw despite no resource change.

I think we should preserve the shared provider instance when the final customized resource is equivalent to the configured resource, with integration tests asserting shared provider identity across all three signals.

Comment on lines +167 to 174
SdkTracerProviderBuilder setDefaultSdkResourceProvider(SdkResourceProvider resourceProvider) {
requireNonNull(resourceProvider, "resourceProvider");
if (resourceSource == ResourceSource.UNSET
|| resourceSource == ResourceSource.DEFAULT_PROVIDER) {
this.resourceProvider = resourceProvider;
this.resourceSource = ResourceSource.DEFAULT_PROVIDER;
}
return this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This puts autoconfigure policy into the SDK builders. All three gain default-vs-explicit provider semantics and four-state bookkeeping to accommodate autoconfigure's customizer lifecycle.

I think we should keep the decision about shared provider attachment in autoconfigure, after customizers run, rather than introducing a second provider-setting mode in each SDK builder. This would require using reflection against the provider builder's internal resource tracking fields.

Resource resource,
SpiHelper spiHelper,
List<Closeable> closeables) {
SdkResourceProvider resourceProvider = SdkResourceProvider.create(resource);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could resource configuration build the SdkResourceProvider from individually named resource contributions instead of wrapping the final merged resource? This collapses the default resource and all detector results into one unnamed constant, losing their source structure. The declarative path does the same. Preserving those contributions would provide the foundation for per-detector refresh later, while retaining existing merge, filtering, and customization behavior.


SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder();
tracerProviderBuilder.setResource(resource);
SdkTracerProviderUtil.setDefaultSdkResourceProvider(tracerProviderBuilder, resourceProvider);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the tracer, meter, and logger provider-customizer Javadocs to recommend addResourceCustomizer() instead of calling setResource() or addResource() on individual signal builders. Explain that provider-level resource customization can opt that signal out of the shared SDK resource provider, and that setResource() also replaces detected resources and resource-customizer results. The concrete builder methods should inherit or include this guidance so it is visible from either API.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants